home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / mouse.exe / MOUSESTK.PAS < prev    next >
Pascal/Delphi Source File  |  1989-05-31  |  5KB  |  98 lines

  1.  
  2. { This is the MOUSESTK.PAS include file for the MOUSE.PAS unit}
  3. { This include file contains the mouse status stack procedures }
  4.  
  5. {---------------------------------------------------------------------------}
  6. { Mouse stack variables }
  7. type
  8.      MousePtrP   = ^MousePtrRec;               {defines a mouse stack record}
  9.      MousePtrRec = record      {Prev points to previous stack record on heap}
  10.         Prev : MousePtrP;                {if nil then is top record on stack}
  11.         Buf  : Pointer;                  {Buf points to the mouse data saved}
  12.         Size : Integer;                    {Size = bytes in the mouse buffer}
  13.      end;
  14.  
  15. var  MouseStack  : MousePtrP;  {MouseStack points to last rec on mouse stack}
  16.                                   {if nil then there is nothing on the stack}
  17.  
  18. {---------------------------------------------------------------------------}
  19. function PushMouse:Boolean;  {Pushes current mouse status on the mouse stack}
  20. var Ptemp : MousePtrP;       {Returns false if not enough heap space to push}
  21.  
  22. begin
  23.   PushMouse := false;                      {<-- assume no good to begin with}
  24.   if not(MouseInstalled) then Exit;             {<-- can't do this, no mouse}
  25.  
  26.   MouseBusy := true;        {disallow re-entrant use of routine by mouse ISR}
  27.   MouseReg.AX := 21;                         {find out how much data to save}
  28.   intr($33,MouseReg);                  {then check to see if it can be saved}
  29.   If MaxAvail < ( MouseReg.BX + sizeof(MousePtrRec) ) then
  30.   begin
  31.     MouseBusy := false;                {Polled use of read mouse is done now}
  32.     Exit;
  33.   end;
  34.  
  35.   Ptemp := MouseStack;                           {<-- save old stack pointer}
  36.   GetMem(MouseStack,sizeof(MousePtrRec));      {<-- get a new pointer record}
  37.   with MouseStack^ do
  38.   begin
  39.     Prev := Ptemp;                            {<-- link in old stack pointer}
  40.     Size := MouseReg.BX;                       {<-- save how big the data is}
  41.     GetMem(Buf,Size);               {<-- grab some buffer space for the data}
  42.     MouseReg.AX := 22;
  43.     MouseReg.ES := seg(Buf^);             {save the Mouse data in the buffer}
  44.     MouseReg.DX := ofs(Buf^);
  45.     intr($33,MouseReg);
  46.   end;
  47.   MouseBusy := false;                  {Polled use of read mouse is done now}
  48.   PushMouse := true;                               {<-- tell them we made it}
  49. end;
  50.  
  51. {---------------------------------------------------------------------------}
  52. function PopMouse:Boolean;          {Pops mouse status from the mouse stack.}
  53. var Ptemp : MousePtrP;                     {Returns false if nothing to pop.}
  54.  
  55. begin
  56.   PopMouse := false;                       {<-- assume no good to begin with}
  57.   if not(MouseInstalled) then Exit;             {<-- can't do this, no mouse}
  58.   If MouseStack <> nil then Exit;           {<-- Nothing in the stack to pop}
  59.  
  60.   MouseBusy := true;        {disallow re-entrant use of routine by mouse ISR}
  61.   with MouseStack^ do
  62.   begin
  63.     MouseReg.AX := 23;
  64.     MouseReg.ES := seg(Buf^);             {restore mouse data from the stack}
  65.     MouseReg.DX := ofs(Buf^);
  66.     intr($33,MouseReg);
  67.     Ptemp := Prev;                              {<-- unlink the prev pointer}
  68.     FreeMem(Buf,Size);                           {and free up the heap space}
  69.     FreeMem(MouseStack,sizeof(MousePtrRec));
  70.     MouseStack := Ptemp;                           {<-- update stack pointer}
  71.   end;
  72.   PopMouse := true;                                {<-- tell them we made it}
  73.   MouseBusy := false;                  {Polled use of read mouse is done now}
  74. end;
  75.  
  76. {---------------------------------------------------------------------------}
  77. procedure ZapMouseStack;                             {Get rid of mouse stack}
  78. var Ptemp : MousePtrP;
  79.  
  80. begin
  81.    MouseBusy := true;       {disallow re-entrant use of routine by mouse ISR}
  82.    while MouseStack <> nil do               {pop the stack until it is empty}
  83.    begin
  84.      with MouseStack^ do
  85.      begin
  86.        Ptemp := Prev;                           {<-- unlink the prev pointer}
  87.        FreeMem(Buf,Size);                        {and free up the heap space}
  88.        FreeMem(MouseStack,sizeof(MousePtrRec));
  89.        MouseStack := Ptemp;                        {<-- update stack pointer}
  90.      end;
  91.    end;
  92.    MouseBusy := false;                 {Polled use of read mouse is done now}
  93. end;
  94.  
  95. {---------------------------------------------------------------------------}
  96. { End Of MOUSESTK.PAS include file }
  97.  
  98.